import PureServiceManageSearch from '../components/service-manager-search';
import * as ServiceAction from 'actions/service';
import { getFetchStatus } from 'actions/util';
import {setEnvironmentId,getEnvironmentId} from 'actions/environment';
import * as ReactRedux from 'react-redux';
import * as React from 'react';

const mapStateToProps = (state) => {
  return {
    isFetching: getFetchStatus(state, ServiceAction.fetchServiceBySearch),
    services: state.serviceList
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    clearServiceList() {
      dispatch(ServiceAction.clearServiceBySearch());
    },
    onFormSubmit(query) {
      dispatch(ServiceAction.fetchServiceBySearch(query));
    },
  };
};

class ServiceManageSearch extends React.Component {
  componentDidMount() {
    setEnvironmentId(this.props.record.id)
    this.props.clearServiceList()
  }

  render() {
    return <PureServiceManageSearch {...this.props}/>;
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(ServiceManageSearch);
